<?php

// TODO this should have a base class, leaving that out because it would make file search more difficult in config_widgets.php
class Widget1 {
  const TITLE_TOKEN = '<!-- widget_title -->';
  const TEXT_TOKEN = '<!-- widget_text -->';
  private $output = '';

  function __construct($title = 'Widget1',$text = 'Default Text') {
    // some of these strings should be moved into a base class and managed using some variable for the file name
    if($s = file_get_contents("templates/Widget1.inc")) {
      error_log('Widget1::__construct() - '.$s);
      if(strpos($s, $this::TITLE_TOKEN) > 0) {
        $s = str_replace($this::TITLE_TOKEN, $title, $s);
      }
      if(strpos($s, $this::TEXT_TOKEN)) {
        $s = str_replace($this::TEXT_TOKEN, $text, $s);
      }
      $this->output = $s;
    } else {
      error_log("Widget1: Could not read file: templates/Widget1.inc");
    }
  }

  function to_string() {
    return $this->output;
  }
}
?>
